
import QtQuick 2.0
import QtQuick.Controls 1.0
import "./Keyboard"
import "./content"
import "./Manage"
import "./Setting"
import CustomComponents 1.0
Rectangle {
    id:root
    width: 800
    height: 480
    color: "#252126"
    property int hour: 12
    property int minute: 12
    property string currentDateAndTime: ""
    Component.onCompleted: {
        db.setLogin("admin","admin","0");
    }
    Db_BMSA{
        id:db
    }

    Mes{
        id:mes
        enabled: false
    }

    Manage_Topic{
        id:topic
        enabled: false
        onEnter: {
            if(mes.order!=order){
                mes.name=name
                mes.order=order
                mes.listview.list.clear();
            }
            root.state="mes"
            //            mes.enabled=true;
            //            topic.visible=false;
            //            topic.enabled=false;
            console.debug("mes");
        }
    }

    Loginn{
        id:login
        onEnter: {
            db.initialize();
            if(login.pass.toString()==db.getLogin(login.user)){
                login.clear()
                root.state="topic"
                //                topic.enabled=true;
                //                login.visible=false;
                //                login.enabled=false;

                console.debug("login");
            }
            console.debug(login.pass.toString());
        }
        Component.onCompleted: {
            til.enabled=false
        }

    }
    Setting{
        id:setting
        enabled: false
        y:-root.height
        onLogoff: {

            root.state="login"
        }

    }


    //    Page{

    //    }

    Titlebar{
        id:til
        titleBarText: "Breeding Managment System"
        dateAndTime: currentDateAndTime
        onHomePressed: {

            root.state="topic"
        }
        onSetting: {
            til.olds=root.state.toString();
            root.state="setting"
        }
        onResome: {
            root.state=til.olds
        }



    }
    function updateTime() {
        var dateAndTime = new Date();
        var timeString = Qt.formatDateTime(dateAndTime, "dddd, dd.MM.yyyy | hh:mm");
        hour = Qt.formatDateTime(dateAndTime, "hh");
        minute = Qt.formatDateTime(dateAndTime, "mm");
        currentDateAndTime = timeString;
    }
    Timer{
        interval: 500
        onOut: {
            updateTime();
        }
    }

    states: [
        // In state 'middleRight', move the image to middleRightRect
        State {
            name: "login"
            PropertyChanges { target: login; opacity: 1; enabled: true}
            PropertyChanges { target: mes; opacity: 0; enabled: false ; }
            PropertyChanges { target: topic; opacity: 0; enabled: false;}
            PropertyChanges { target: setting; opacity: 0; enabled: false;}
             PropertyChanges { target: setting;   y:-root.height}
             PropertyChanges { target: til; titleHomeButton.enabled:false;}
             PropertyChanges { target: til; enabled: false;}
        },

        State {
            name: "mes"
            PropertyChanges { target: mes; opacity: 1; enabled: true}
            PropertyChanges { target: login; opacity: 0; enabled: false;}
            PropertyChanges { target: topic;opacity: 0; enabled: false;}
            PropertyChanges { target: setting; opacity: 0; enabled: false;}
            PropertyChanges { target: til; enabled: true;}
            PropertyChanges { target: til; titleHomeButton.enabled:true;}
            PropertyChanges { target: login;x:root.width}
            PropertyChanges { target: topic;x:root.width}

        },
        State {
            name: "topic"
            PropertyChanges { target: topic; opacity: 1; enabled: true}
            PropertyChanges { target: mes; opacity: 0; enabled: false;}
            PropertyChanges { target: login; opacity: 0; enabled: false;}
            PropertyChanges { target: setting; opacity: 0; enabled: false;}
            PropertyChanges { target: til; enabled: true;}
            PropertyChanges { target: til; titleHomeButton.enabled:true;}

            PropertyChanges { target: mes; x:root.width}
            PropertyChanges { target: login; x:root.width}
        },
        State {
            name: "setting"
            PropertyChanges { target: setting; opacity: 1; enabled: true}
            PropertyChanges { target: mes; opacity: 0; enabled: false;}
            PropertyChanges { target: login; opacity: 0; enabled: false;}
            PropertyChanges { target: topic; opacity: 0; enabled: false;}
            PropertyChanges { target: til; enabled: true;}
            PropertyChanges { target: til; titleHomeButton.enabled:false;}
            PropertyChanges { target: setting; y:0}

         }
    ]


    transitions: [

        // When transitioning to 'middleRight' move x,y over a duration of 1 second,
        // with OutBounce easing function.
        Transition {
            from: "*"; to: "login"
            NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce; duration: 1000 }
            NumberAnimation { properties: "opacity"; easing.type: Easing.OutBounce; duration: 1000 }

        },

        // When transitioning to 'bottomLeft' move x,y over a duration of 2 seconds,
        // with InOutQuad easing function.
        Transition {
            from: "*"; to: "mes"
            NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce; duration: 1000 }
            NumberAnimation { properties: "opacity"; easing.type: Easing.OutBounce; duration: 1000 }
        },

        // For any other state changes move x,y linearly over duration of 200ms.
        Transition {
            NumberAnimation { properties: "x,y"; easing.type: Easing.OutBounce; duration: 1000 }
           // NumberAnimation { properties: "opacity"; easing.type: Easing.OutBounce; duration: 1000 }
        }
    ]

}
